package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.Timer;

public class DigitalClock extends JLabel
{
	private String pattern;
	private Timer timer;
	private int delay;

	public DigitalClock(String pattern)
	{
		this.pattern = pattern;
		this.delay = 1000;
		createTimer();
		this.timer.start();
	}

	public DigitalClock()
	{
		this.pattern = "HH:mm:ss";
		this.delay = 1000;
		createTimer();
		this.timer.start();
	}

	private void createTimer() {
		this.timer = new Timer(this.delay, new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DigitalClock.this.setText(new SimpleDateFormat(DigitalClock.this.pattern).format(new Date()));
			} } );
	}

	public String getPattern() {
		return this.pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public Timer getTimer() {
		return this.timer;
	}

	public int getDelay() {
		return this.delay;
	}

	public void setDelay(int delay) {
		this.delay = delay;
	}
}